<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文本</title>
<link href="../../../static/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>库存管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li>仓库名称:
        <input maxlength="50" id="cName" type="text" />
      </li>
      <li>商品品牌:
        <input maxlength="50" id="Brand" type="text" />
      </li>
      <li>商品类型:
        <input maxlength="50" id="Type" type="text" />
      </li>
      <li>商品名称:
        <input maxlength="50" id="Product" type="text" />
      </li>
      <li class="subBut" id="searchBtn"><img src="../../../static/images/t06.png" />查询</li>
    </ul>
    <table id="stockList" class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>仓库名称</th>
          <th>商品品牌</th>
          <th>商品类型</th>
          <th>商品名称</th>
          <th>厂商名称</th>
          <th>商品数量</th>
          <th>单位</th>
        </tr>
      </thead>
      <tbody>
<!--        <tr>-->
<!--          <td>4</td>-->
<!--          <td>南京21号仓库</td>-->
<!--          <td>联想</td>-->
<!--          <td>笔记本</td>-->
<!--          <td>X260i</td>-->
<!--          <td>北京联想科技股份有限公司</td>-->
<!--          <td>100</td>-->
<!--          <td>台</td>-->
<!--        </tr>-->
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i id="total" class="blue">0</i>条记录，当前显示第&nbsp;<i id="current" class="blue">1</i>页</div>
      <ul id="paginListNum" class="paginList">
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">1</a></li>-->
<!--        <li class="paginItem current"><a href="javascript:;">2</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
      </ul>
    </div>
  </form>
</div>
<script type="text/javascript">
	// $('.tablelist tbody tr:odd').addClass('odd');

    var isSerch = false;
    $(function () {
      loadStocks(1);
      // 搜索点击事件
      $("#searchBtn").on("click", function () {
        isSerch = true;
        // alert($('#cName').val());
        // alert($('#Brand').val());
        // alert($('#Type').val());
        // alert($('#Product').val());
         loadStocks(1);
      })

    });

    //加载库存列表
    function loadStocks(currentPage) {
      let cName;
      let Brand;
      let Type;
      let Product;
      if (isSerch) {
        cName= $('#cName').val();
        Brand=$('#Brand').val();
        Type=$('#Type').val();
        Product=$('#Product').val();
      }

      let nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
      let nowUserID = nowUser.uid;
      //跳转servlet路径、传入参数、获取返回值——页面片段并显示！
      $.ajax({
        type: "GET",//请求类型
        url: "/Stock/StockPage",//请求的url
        data: {
          cNameLike: cName,
          brandLike: Brand,
          typeLike: Type,
          productLike: Product,
          userID:nowUserID,
          pageNum: currentPage,
          pageSize: 6
        },//请求参数
        dataType: "json",//ajax接口（请求url）返回的数据类型
        success: function (pb) {
          pb = pb.data;
          $("#total").html(pb.totalCount)
          $("#current").html(pb.pageNum)
          //1.展示分页页码
          var lis = "";
          //上一页
          var beforenum = pb.pageNum - 1;
          if (beforenum <= 0) {
            beforenum = 1;
          }
          var beforePage = '<li class="paginItem" onclick="loadStocks(' + beforenum + ')"><a href="javascript:;"><span class="pagepre"></span></a></li>';
          lis += beforePage;

          // 1,2,3,4...
          // 定义开始位置begin,结束位置 end
          var begin; // 开始位置
          var end; //  结束位置

          //要显示6个页码
          if (pb.totalPage < 6) {
            //总页码不够10页
            begin = 1;
            end = pb.totalPage;
          } else {
            //总页码超过6页
            begin = pb.pageNum - 3;
            end = pb.pageNum + 2;
            //2.如果前边不够3个，后边补齐6个
            if (begin < 1) {
              begin = 1;
              end = begin + 5;
            }
            //3.如果后边不足2个，前边补齐6个
            if (end > pb.totalPage) {
              end = pb.totalPage;
              begin = end - 5;
            }
          }
          for (var i = begin; i <= end; i++) {
            var li;
            //判断当前页码是否等于i
            if (pb.pageNum == i) {
              li = '<li class="paginItem current" onclick="loadStocks(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            } else {
              //创建页码的li
              li = '<li class="paginItem" onclick="loadStocks(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            }
            //拼接字符串，加入页面中
            lis += li;
          }

          //下一页
          var nextnum = pb.pageNum + 1;
          if (nextnum > pb.totalPage) {
            nextnum = pb.totalPage;
          }
          var nextPage = '<li class="paginItem" onclick="loadStocks(' + nextnum + ')"><a href="javascript:;"><span class="pagenxt"></span></a></li>';
          lis += nextPage;

          $("#paginListNum").html(lis);//显示

          // 3.显示当前页列表
          let stock_lis = '';
          for (var i = 0; i < pb.data.length; i++) {

            let stock = pb.data[i];//该页路线数据显示        showOrder(id)

            let stockli =
                    '<tr>' +
                    '<td>' +
                    '<span>' + ((pb.pageNum - 1) * 6 + i + 1) + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.warehouseName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.brandName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.typeName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.productName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.firmName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.number+ '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + stock.productUnit + '</span>' +
                    '</td>' +

                    '</tr>';
            stock_lis += stockli;
          }
          $("#stockList tbody").html(stock_lis);

        }
      })
    }
</script>
</body>
</html>
